package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.AppMainDiscountZone;
import com.addplus.townmall.server.api.model.town.expand.AppMainDiscountZoneExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * App商城首页折扣 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface AppMainDiscountZoneMapper extends BaseAddMapper<AppMainDiscountZone> {


    @Select("SELECT\n" +
            " a.id,\n" +
            " a.store_id,\n" +
            " s.store_name ,\n" +
            " a.shop_product_id,\n" +
            " a.shop_sku_id,\n" +
            " a.shop_name,\n" +
            " a.shop_tag,\n" +
            " a.shop_seal_img,\n" +
            " a.line_price,\n" +
            " a.sale_price,\n" +
            " a.discount_rate\n" +
            "FROM\n" +
            " app_main_discount_zone a\n" +
            " LEFT JOIN store s ON s.id = a.store_id AND s.is_delete = 0\n" +
            " WHERE a.is_delete = 0\n" +
            " ORDER BY a.sort \n" +
            " limit #{countList}")
    List<AppMainDiscountZoneExpand> getAppMainDiscountZoneLimit(@Param("countList") Integer countList);
    @Select("select IFNULL(max(sort)+1,1) as sort from app_main_discount_zone WHERE is_delete = 0")
    Integer maxSort();

    @Select("select s.store_name,a.* " +
            "from app_main_discount_zone  a " +
            "inner JOIN store  s ON s.id = a.store_id where a.is_delete=0  ORDER BY a.gmt_modified DESC")
    List<AppMainDiscountZoneExpand> getAllAppMainDiscountZone(IPage page);

}
